do STARdata

*choice of outcome of interest
gen Y = math 

*controls: school ID by free lunch status fixed effects
xi i.poor*i.schid 
keep Y _I* D Z poor schid 

*observations for which outcome is missing
gen miss= missing(Y)

*generate influence function, for which average treatment effects are to be estimated
generateIF Y, `mean' `variance' quantile(0.5) 
gen IF1upper = D*IF + (1-D)*IFupper
gen IF1lower = IF    
gen IF0upper = IF    
gen IF0lower = (1-D)*IF + D*IFlower

 
*export regressors and controls for all observations 
outsheet D Z poor schid miss _I*  using regressors.csv, comma replace
 
*export influence functions for observations where outcome is not missing
drop if missing(Y) 
outsheet IF1upper IF1lower IF0upper IF0lower using IFbounds.csv, comma replace 
 
